package mlp.game.shadownbolts;

import com.playtomic.android.api.Playtomic;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;

public class IntroActivity extends Activity {
	public static final String URL_TWITTER = "https://twitter.com/OV3RK1LL";
	public static final String URL_FACEBOOK = "http://www.facebook.com/PonyGameCollection";
	public static final String URL_PAYPAL = "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=UYQJSSAKZNMFY";
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		 super.onCreate(savedInstanceState);
	     setContentView(R.layout.intro);
	     try {
	    	 Playtomic.getInstance(
	    			 5725, 
	    			 "82896f9523324110", 
	    			 "2aaa223eaf5247c0bbc196a41d7b2e", 
	    			 this);
	    	 Playtomic.Log().view();
	     } catch (Exception e) {
	    	 e.printStackTrace();
	     }	  
	     
	     final View flashUnder = findViewById(R.id.flashUnder);
	     
	     AlphaAnimation a1 = new AlphaAnimation(0, 1);
	     a1.setDuration(100);
	     a1.setRepeatCount(0);
	     a1.setRepeatMode(AlphaAnimation.REVERSE);
	     a1.setStartOffset((long) (1000 + Math.random() * 1000));
	     a1.setAnimationListener(new AnimationListener() {			
			@Override
			public void onAnimationStart(Animation animation) {}			
			@Override
			public void onAnimationRepeat(Animation animation) {}			
			@Override
			public void onAnimationEnd(Animation animation) {
				animation.setStartOffset((long) (Math.random() * 8000));		
				flashUnder.startAnimation(animation);
			}
	     });
	     flashUnder.startAnimation(a1);    
	}
	
	public void onStartClick(View view) {
		Intent i = new Intent(this, GameActivity.class);
		i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
		overridePendingTransition(0, 0);
		finish();
		overridePendingTransition(0, 0);
		startActivity(i);
	}
	
	public void onHelpClick(View view) {
		Playtomic.Log().customMetric("Help",  "Screens", false); 
		new AlertDialog.Builder(this)
		.setIcon(android.R.drawable.ic_dialog_info)
		.setTitle(R.string.btnHelp)
		.setMessage(R.string.help_dialog_message)
		.setPositiveButton(android.R.string.yes, null)
		.show();
	}
	
	public void onExtraClick(View view) {
		Intent i = null;
		switch (view.getId()) {
		case R.id.btnDonate:
			i = new Intent(Intent.ACTION_VIEW, Uri.parse(URL_PAYPAL));
			break;
		case R.id.btnFacebook:
			i = new Intent(Intent.ACTION_VIEW, Uri.parse(URL_FACEBOOK));
			break;
		case R.id.btnTwitter:
			i = new Intent(Intent.ACTION_VIEW, Uri.parse(URL_TWITTER));
			break;
		default:
			break;
		}
		if(i != null)
			startActivity(i);
	}	
}
